﻿@{
    ViewBag.Title = "设备图表";
}
<script src="~/Content/highcharts/highcharts.js"></script>
<script src="~/Content/highcharts/highcharts-3d.js"></script>

<div id="sincos" class="center" style="min-width: 600px;height:500px;">
    </div>


<script>
    $(function () {
        var div='sincos';
        var title='设备分布表';
        var url='@Url.Action("ChartType", "FactoryMachines")';
        var name='设备分布';
        var chart = new Highcharts.Chart({
            chart: {
                renderTo: div,
                type: 'pie',
                options3d: {
                    enabled: true,
                    alpha: 45,
                    beta: 0
                }
            },
            credits: {
                enabled: false},
            title: {
                text: title
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    depth: 35,
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            },
            series: create(url,name)
        });
    });
    function getdata(url) {
        var data1 = new Array();
        $.ajax({
            type: "POST",
            url: url,
            data: {},
            async: false, //表示同步，如果要得到ajax处理完后台数据后的返回值，最好这样设置
            success: function (result) {
                for (var i in result) {
                    data1.push({ "name": result[i].Name, "y": result[i].Number });
                }
            }
        });
        return data1;
    };
    function create(url, name) {
        var series = new Array();
        series.push({
            type: 'pie',
            name: name,
            data: getdata(url)
        });
        return series;
    };
    </script>
